package com.xiaoyang.controller;

import com.xiaoyang.dto.ResultDTO;
import com.xiaoyang.service.UserService;
import com.xiaoyang.service.WxPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guoziyang
 * @create 2020/9/23 7:37 下午
 */

@RestController
@RequestMapping("/api")
public class LogoutController {

    @Autowired
    private UserService userService;

    @Autowired
    private WxPushService wxPushService;

    @Value("${CALLBACK_URL}")
    private String CALLBACK_URL;

    @GetMapping("/logout")
    public ResultDTO logout(@RequestParam("uid") String uid) {
        int i = userService.deleteUserByUid(uid);
        if (i < 1) {
            return new ResultDTO(401, "用户不存在");
        }
        wxPushService.wxPush("您成功退出登录", "UID_" + uid);
        String url = CALLBACK_URL + "/#/api/login?uid=" + uid;
        String content = "\uD83D\uDC49<a href=\"" + url + "\">点击登录今日校园</a>\uD83D\uDC48";
        wxPushService.wxPush(content, "UID_" + uid);
        return new ResultDTO(201, "退出登录成功");
    }

}
